package com.sz.admin.dtuftpinfo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import com.sz.core.common.entity.ApiPageResult;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.constant.GlobalConstant;
import com.sz.core.common.entity.PageResult;
import com.sz.core.common.entity.SelectIdsDTO;
import com.sz.admin.dtuftpinfo.service.DtuFtpInfoService;
import com.sz.admin.dtuftpinfo.pojo.dto.DtuFtpInfoCreateDTO;
import com.sz.admin.dtuftpinfo.pojo.dto.DtuFtpInfoUpdateDTO;
import com.sz.admin.dtuftpinfo.pojo.dto.DtuFtpInfoListDTO;
import com.sz.admin.dtuftpinfo.pojo.dto.DeviceBindDTO;
import com.sz.admin.dtuftpinfo.pojo.dto.DeviceUnbindDTO;
import com.sz.admin.dtuftpinfo.pojo.vo.DtuFtpInfoVO;
import com.sz.core.common.entity.ImportExcelDTO;
import jakarta.servlet.http.HttpServletResponse;

/**
 * <p>
 * DtuFtpInfo Controller
 * </p>
 *
 * @author sz-admin
 * @since 2025-10-20
 */
@Tag(name = "DtuFtpInfo管理")
@RestController
@RequestMapping("dtu-ftp-info")
@RequiredArgsConstructor
public class DtuFtpInfoController {

    private final DtuFtpInfoService dtuFtpInfoService;

    @Operation(summary = "新增DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.create", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping
    public ApiResult<Void> create(@RequestBody DtuFtpInfoCreateDTO dto) {
        dtuFtpInfoService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.update", orRole = GlobalConstant.SUPER_ROLE)
    @PutMapping
    public ApiResult<Void> update(@RequestBody DtuFtpInfoUpdateDTO dto) {
        dtuFtpInfoService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.remove", orRole = GlobalConstant.SUPER_ROLE)
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        dtuFtpInfoService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping
    public ApiResult<PageResult<DtuFtpInfoVO>> list(DtuFtpInfoListDTO dto) {
        return ApiPageResult.success(dtuFtpInfoService.page(dto));
    }

    @Operation(summary = "详情DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/{id}")
    public ApiResult<DtuFtpInfoVO> detail(@PathVariable Object id) {
        return ApiResult.success(dtuFtpInfoService.detail(id));
    }

    @Operation(summary = "导入DtuFtpInfo")
    @Parameters({
      @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "dtu.ftp.info.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        dtuFtpInfoService.importExcel(dto);
    }

    @Operation(summary = "导出DtuFtpInfo")
    @SaCheckPermission(value = "dtu.ftp.info.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody DtuFtpInfoListDTO dto, HttpServletResponse response) {
        dtuFtpInfoService.exportExcel(dto, response);
    }

    @Operation(summary = "设备绑定部门")
    @SaCheckPermission(value = "dtu.ftp.info.bind", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping("/bind")
    public ApiResult<Void> bindDevice(@RequestBody DeviceBindDTO dto) {
        dtuFtpInfoService.bindDevice(dto);
        return ApiResult.success();
    }

    @Operation(summary = "设备解绑部门")
    @SaCheckPermission(value = "dtu.ftp.info.unbind", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping("/unbind")
    public ApiResult<Void> unbindDevice(@RequestBody DeviceUnbindDTO dto) {
        dtuFtpInfoService.unbindDevice(dto);
        return ApiResult.success();
    }

    @Operation(summary = "根据部门ID分页查询设备")
    @SaCheckPermission(value = "dtu.ftp.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/dept/{deptId}")
    public ApiResult<PageResult<DtuFtpInfoVO>> pageByDeptId(@PathVariable Long deptId, DtuFtpInfoListDTO dto) {
        return ApiPageResult.success(dtuFtpInfoService.pageByDeptId(deptId, dto));
    }
}